/**
 * Copyright 2013 Mr.Hai Mobile Developer. All rights reserved.
 * HAI PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.hector.meinewerk.common;

import java.io.Serializable;

import com.hector.meinewerk.constants.Constants;
import com.hector.meinewerk.dto.UserDTO;
import com.hector.meinewerk.utils.GlobalUtils;
import com.hector.meinewerk.utils.StringUtil;

@SuppressWarnings("serial")
public class Profile implements Serializable {
	public static final String APP_PROFILE = "appProfile";
	private boolean isLogin = false;
	private String versionName = Constants.STR_BLANK;
	// revision cua thu muc cache hinh anh
	private String server_revision = "";
	private UserDTO userData = new UserDTO();
	public boolean bNoticeOutMainScreen = true;
	// is mode debug or not
	private boolean isDebugMode = true;

	/**
	 * set chuoi server revision
	 * 
	 * @author: HaiTC
	 */
	public void setServerRevision(String revision) {
		this.server_revision = revision;
		save();
	}

	/**
	 * Tra ve chuoi server revision
	 * 
	 * @author: HaiTC
	 */
	public String getServerRevision() {
		return server_revision;
	}

	/**
	 * @return the isDebugMode
	 */
	public boolean isDebugMode() {
		return isDebugMode;
	}

	/**
	 * @param isDebugMode
	 *            the isDebugMode to set
	 */
	public void setDebugMode(boolean isDebugMode) {
		this.isDebugMode = isDebugMode;
		save();
	}

	public void setMyCell() {
		save();
	}

	public void setLogin(boolean isLogin) {
		this.isLogin = isLogin;
		save();
	}

	public boolean isLogin() {
		return isLogin;
	}

	public void setUserData(UserDTO userData) {
		this.userData = userData;
		save();
	}

	public UserDTO getUserData() {
		return userData;
	}

	/**
	 * @return the versionName
	 */
	public String getVersionName() {
		return versionName;
	}

	/**
	 * @param versionName
	 *            the versionName to set
	 */
	public void setVersionName(String versionName) {
		if (!StringUtil.isNullOrEmpty(versionName)) {
			int length = versionName.length();
			if (length == 3) {
				versionName += "0";
			} else if (length == 5) {
				String lastChar = versionName.substring(length - 1, length);
				versionName = versionName.substring(0, 3) + lastChar;
			}
		}
		this.versionName = versionName;
		save();
	}

	public void setMyGPSInfo() {
		save();
	}

	public void save() {
		GlobalUtils.saveObject(this, Profile.APP_PROFILE);
	}
}
